<?php
require_once("dbtools.inc.php");
$id=$_COOKIE['id'];
$correct_t=$_COOKIE['correct'];

$link = create_connection();
$sql="select * from users where id=$id and status='normal'";
$result=@execute_sql($link,'zhihu',$sql);

$user = @mysqli_fetch_object($result)->username;
$user = $user.'thonsun123';
if($correct_t!=md5($user)){
    @mysqli_free_result($result);
    @mysqli_close($link);
    header("location:login.php");
}

$answers_id=isset($_GET['answers_id'])?$_GET['answers_id']:1;
$sql="select qst_id from answers where id=$answers_id";
$result=execute_sql($link,'zhihu',$sql);
//var_dump($sql);
$question_id=mysqli_fetch_object($result)->qst_id;

if ($_GET['answers_id'] and $_GET['like']==1){
    $sql="update answers set agree=agree+1 where id=$answers_id";
    $result=execute_sql($link,'zhihu',$sql);

    @mysqli_free_result($result);
    @mysqli_close($link);
    header("location:question_detail.php?questionid=$question_id");
} else if ($_GET['answers_id'] and $_GET['like']==0){
    $sql="update answers set disagree=disagree+1 where id=$answers_id";
    $result=execute_sql($link,'zhihu',$sql);

    @mysqli_free_result($result);
    @mysqli_close($link);
    header("location:question_detail.php?questionid=$question_id");
}
?>